package com.ytf.test.sixth;

/**
 * @author: YTF
 * @date: 2024/9/23 12:42
 * @version: 1.0
 * @description:
 */
public class Lunch {

    public static void main(String[] args) {
        //！ Soup1 soup1 =new Soup1(); //private 不能new
        Soup1 soup1 = Soup1.createSoup1();
        Soup2 soup2 = Soup2.createSoup2();
        soup2.f();

        /**
         * Output:
         *  Soup1 constructor
         *  Soup2 constructor
         *  Soup2.f()
         *
         * 总结：
         *  注意权限修饰词和范围
         *  Soup2 和 Soup1 右创建细家方面的不同。
         *  Soup2 用到了设计模式，singleton(单例模式)
         */
    }
}

class Soup1 {
    private Soup1() {
        System.out.println("Soup1 constructor");
    }

    public static Soup1 createSoup1() {
        return new Soup1();
    }
}

class Soup2 {
    private Soup2() {
        System.out.println("Soup2 constructor");
    }

    private static Soup2 soup2 = new Soup2();

    public static Soup2 createSoup2() {
        return soup2;
    }
    public void f(){
        System.out.println("Soup2.f()");
    }
}
